﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace ZMHWcfServiceLibrary
{
    public static class DebugHelper
    {
        public const bool IncludeExceptionDetailInFaults =
    #if DEBUG
            true; 
    #else 
            flase
    #endif
    }
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码和配置文件中的类名“FaultExceptionSVC”。
    [ServiceBehavior(IncludeExceptionDetailInFaults = DebugHelper.IncludeExceptionDetailInFaults)]
    public class FaultExceptionSVC : IFaultExceptionSVC
    {
        public double Add(double number1, double number2)
        {
            return number1 + number2;
        }

        public double Divide(double number1, double number2)
        {
            if (number2 == 0)
            {
                DivideByZeroException exception = new DivideByZeroException();
                throw new FaultException<DivideByZeroException>(exception, "number2 is 0");
            }
            return number1 / number2;
        }

        public void MethodWithError()
        {
            InvalidOperationException exception = new InvalidOperationException("Some error.");
            ExceptionDetail detail = new ExceptionDetail(exception);
            throw new FaultException<ExceptionDetail>(detail, exception.Message);
        }
    }
}
